package com.baiduspring.web.user;

import com.baiduspring.dao.entity.User;
import com.baiduspring.utils.servlet.WebUtils;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Objects;

public class LoginStatus {
    public static void status(HttpServletRequest request, ModelAndView view) {
        HttpSession session = request.getSession();
        Object o = session.getAttribute("user");
        if (Objects.isNull(o)) {
            view.addObject("loginStatus", false);
        } else {
            User user = (User)o;
            view.addObject("user", user);
            view.addObject("loginStatus", true);
        }

        view.addObject("isMobile", WebUtils.requestSource(request));
    }
}
